package com.itbaizhan.controller;

import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import com.alibaba.cloud.ai.dashscope.chat.MessageFormat;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.image.*;
import org.springframework.ai.model.Media;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.net.URI;
import java.util.List;

/**
 * 文生图
 */
@RestController
public class TextToImageController {

    private final ImageModel imageModel;

    @Autowired
    private ChatModel chatModel;


    public TextToImageController(ImageModel imageModel) {
        this.imageModel = imageModel;
    }


    /**
     * 文生图
     * @return
     */
    @GetMapping("/image")
    public String image(String message){
        // 1、设置模型
        ImageOptions imageModelOptions = ImageOptionsBuilder.builder()
                .withModel("wanx-v1")
                .build();
        // 2、图片提示词
        ImagePrompt imagePrompt = new ImagePrompt(message, imageModelOptions);
        // 3、发送请求
        ImageResponse call = imageModel.call(imagePrompt);
        String url = call.getResult().getOutput().getUrl();
        return url;
    }


}
